package com.zhang.spark_2.com.zhang.core.wc1

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable

/**
 * @title:
 * @author: zhang
 * @date: 2022/2/18 08:32 
 */
object WC_countByValue {

  def main(args: Array[String]): Unit = {
    //TODO 获取环境
    val conf = new SparkConf().setMaster("local[*]").setAppName("WordCount")
    val sc = new SparkContext(conf)

    val data: RDD[String] = sc.makeRDD(List(
      "hello scala", "hello spark"
    ))

    val flatRdd: RDD[String] = data.flatMap(_.split(" "))
    flatRdd.countByValue().foreach(println)

    sc.stop()

  }
}
